﻿/**
 * @copyright Copyright 2009 Structured Solutions
 * @license http://www.codeplex.com/ShippingAgent/license Microsoft Public License (Ms-PL)
 * @version 3.2
 */

using System;
using System.Collections;

namespace StructuredSolutions.ShippingAgent
{
    public class NamedAmountList : ArrayList
    {
        public NamedAmount this[string name]
        {
            get
            {
                int index = IndexOf(name);
                if (index > -1)
                {
                    return (NamedAmount)this[index];
                }
                NamedAmount amount = new NamedAmount();
				amount.Amount = 0;
				amount.Name = name;
                Add(amount);
                return amount;
            }    
            set
            {
                int index = IndexOf(name);
                if (index > -1)
                    this[index] = value;
                else
                {
                    Add(value);
                }
            }
        }

        public int IndexOf(string name)
        {
            for(int index = 0; index < Count; index++)
				if (string.Compare(((NamedAmount)this[index]).Name, name, true) == 0)
                    return index;
            return -1;
        }
    }
}